# -*- coding: utf-8 -*-
import os
import sys
from pathlib import Path
from PySide2.QtWidgets import *

from TESS_PythonAPI.Tessng import TessngFactory
from tess_local_simulator.CustomPlugin import CustomPlugin


def start_local_tess_simulator(config_dict: dict):

    app = QApplication()
    workspace = os.fspath(Path(__file__).resolve().parent)
    config = {'__workspace': workspace,
              '__netfilepath': config_dict['netPath'],
              # '__netfilepath': r'net_file\TLS0814_no_emergency.tess',
              '__simuafterload': True,
              '__custsimubysteps': True
              }
    plugin = CustomPlugin(config_dict)
    factory = TessngFactory()
    tessng = factory.build(plugin, config)
    if tessng is None:
        sys.exit(0)
    else:
        sys.exit(app.exec_())
